(function (vc, vm) {
    vc.extends({
        data: {
            editStoreMsgInfo: {
                msgId: '',
                title: '',
                pageUrl: '',
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editStoreMsg', 'openEditStoreMsgModal', function (_params) {
                $that.refreshEditStoreMsgInfo();
                $('#editStoreMsgModel').modal('show');
                vc.copyObject(_params, $that.editStoreMsgInfo);
                $that.editStoreMsgInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editStoreMsgValidate: function () {
                return vc.validate.validate({
                    editStoreMsgInfo: $that.editStoreMsgInfo
                }, {
                    'editStoreMsgInfo.title': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "通知名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "通知名称不能超过128位"
                        },
                    ],
                    'editStoreMsgInfo.pageUrl': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "连接地址不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "512",
                            errInfo: "连接地址超过512位"
                        },
                    ],
                    'editStoreMsgInfo.msgId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "消息ID不能为空"
                        }
                    ]
                });
            },
            editStoreMsg: function () {
                if (!$that.editStoreMsgValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    '/shopMsg.updateShopMsg',
                    JSON.stringify($that.editStoreMsgInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editStoreMsgModel').modal('hide');
                            vc.emit('storeMsgManage', 'listStoreMsg', {});
                            vc.toast("修改成功");
                            return;
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditStoreMsgInfo: function () {
                $that.editStoreMsgInfo = {
                    msgId: '',
                    title: '',
                    pageUrl: '',
                }
            }
        }
    });
})(window.vc, window.vc.component);
